<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String point=(String) request.getSession().getAttribute("coordinatePoint");
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>党员管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=10,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" type="text/css" href="../lib/laydate.css"/>
    <link rel="stylesheet" type="text/css" href="../css/base.css"/>
    <link rel="stylesheet" type="text/css" href="../css/sys/addUser.css"/>
    <script src="../js/jquery/jquery-1.9.1.js" type="text/javascript" charset="utf-8"></script>
    <script src="../lib/laydate.js"></script>
    <script src="/lib/layer/layer.js?20201106"></script>
    <script src="../js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/ajaxupload.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/sys/adduser.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jquery.form.min.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.js"></script>
    <style>
        .clearfix:after {
            content: '';
            display: block;
            clear: both;
        }

        .fl {
            float: left;
        }

    </style>
    <script>
        var priv_id;
        var res;
        var dept_id;
        var user_id;
        var party = $.GetRequest()
        function detail(){
            if(party.edit){
                $.ajax({
                    url:'/OrgPartyMember/selectList',
                    dataType:'json',
                    data:{opId:party.edit},
                    success:function(res){
                        var data=res.obj[0];
                        console.log(data)
                        $('input[name="address"]').val(data.address)
                        $('input[name="addressLocation"]').val(data.addressLocation)
                        $('input[name="birthday"]').val(data.birthday)
                        $('input[name="contactDate"]').val(data.contactDate)
                        $('#staffNameInput').attr("user_id",party.edit)
                        $('#staffNameInput').attr("username",data.name)
                        $('input[name="education"]').val(data.education)
                        $('input[name="extrMember"]').val(data.extrMember)
                        $('input[name="familyName"]').val(data.familyName)
                        $('input[name="memberTypeTo"]').val(data.memberTypeTo)
                        $('input[name="staffName1"]').val(data.name)
                        $('input[name="admissionDate1"]').val(function(){
                            if(data.admissionDate == ""||data.admissionDate == undefined){
                                return ''
                            }else{
                                return new Date(data.admissionDate).Format('yyyy-MM-dd')
                            }
                        }())
//                        becomeDate
                        $('input[name="becomeDate1"]').val(function(){
                            if(data.becomeDate == ""||data.becomeDate == undefined){
                                return ''
                            }else{
                                return new Date(data.becomeDate).Format('yyyy-MM-dd')
                            }
                        }())
                        $('input[name="partyState"]').val(data.partyState)
                        $('input[name="post"]').val(data.post)
                        $('input[name="sex"]').val(data.sex)
                        $('input[name="tel"]').val(data.tel)
                        $('#memberType').val(data.memberType)
                        $(":radio[name='contactNos'][value='" + data.contactNos + "']").prop("checked", "checked");
                        $(":radio[name='flowMemberNos'][value='" + data.flowMemberNos + "']").prop("checked", "checked");
                        var str=data.memberTypeTo;
                        var arr=str.split(',')

                            for(var i=0;i<arr.length;i++){
                                $(':checkbox[value="'+arr[i]+'"]').prop('checked','checked')
                            }

                    }

                })
            }

        }
        $(function () {




            $('#btn1').click(function () {
                if($('#staffNameInput').attr("user_id") == undefined ||$('#staffNameInput').attr("user_id") == ''){
                    $.layerMsg({content:'用户为空',icon:2});
                    return ;
                }
                var userId = $('#staffNameInput').attr("user_id").split(",")[0];
                $.ajax({
                    url: '/OrgPartyMember/selectByUserId',
                    dataType: 'json',
                    data: {UserId: userId},
                    success: function (res) {

                        if(res.object != 0){
                            $.layerMsg({content:'用户重复',icon:2});
                            return;
                        }
                        if (party.type) {
                            var id=party.type;

                            var name = $('#staffNameInput').attr("username").split(",")[0];
                            $('#datasave').attr('action','/OrgPartyMember/insert')
                            var str=''
                            $('.check').each(function(){
                                if($(this).prop('checked') == true){
                                    str += $(this).attr('value')+','
                                }

                            })
//                    $('input[name="memberTypeTo"]').val(str);
                            $('#datasave').ajaxSubmit({
                                type:'post',
                                dataType:'json',
                                data:{orgDeptId:id,memberTypeTo:str,userId:userId,name:name},
                                success:function(res){
                                    if(res.flag){
                                        $.layerMsg({content:'新建成功',icon:1})
                                        parent.opener.ajaxdata(window.opener.numdept)
                                        window.close()
                                    }else{
                                        $.layerMsg({content:'新建失败',icon:1})
                                    }
                                }
                            })
                        }else{
                            var id=party.edit;
                            var newId=party.id
                            $('#datasave').attr('action','/OrgPartyMember/update')
                            var str=''
                            $('.check').each(function(){
                                if($(this).prop('checked') == true){
                                    str += $(this).attr('value')+','
                                }

                            })
//                    $('input[name="memberTypeTo"]').val(str);
                            console.log(str)
                            $('#datasave').ajaxSubmit({
                                type:'post',
                                dataType:'json',
                                data:{opId:id,orgDeptId:newId,memberTypeTo:str},
                                success:function(res){
                                    if(res.flag){
                                        $.layerMsg({content:'编辑成功',icon:1})
                                        parent.opener.ajaxdata(window.opener.numdept)
//                                window.close()
                                    }else{
                                        $.layerMsg({content:'编辑失败',icon:1})
                                    }
                                }
                            })
                        }
                    }
                })




            })
        })
    </script>
</head>
<body>
<div class="content">
    <div class="title">
        <span class="titleTxt">新增党员</span>
        <%--<span>（</span><span class="newname"></span><span>）</span>--%>
    </div>

    <form action="" method="post" name="form1" id="datasave">
        <table cellspacing="0" cellpadding="0" class="tab" style="border-collapse:collapse;background-color: #fff">
            <tr>
                <td colspan="2" style="color: #3eb1f0">党员基本信息</td>
            </tr>
            <tr>
                <td nowrap class="TableData"><span style="color: red;margin-right: 5px;">*</span>姓名:</td><%--雇员--%>
                <td class="TableData">
                    <input type="text" id="staffNameInput" name="staffName1" style="width: 158px;height:28px;" size="12" class="BigStatic" readonly value=""/>
                    <a href="javascript:;" id="" class="userAdd" ><fmt:message code="global.lang.select" /></a><%--选择--%>
                </td>
            </tr>
            <tr>
                <td width="15%">性别：</td>
                <td width="70%">
                    <input type="text" name="sex" value="">
                </td>
            </tr>
            <tr>
                <td width="15%">民族：</td>
                <td width="70%">
                    <input type="text" name="familyName" value="">
                </td>
            </tr>
            <tr>
                <td width="15%">出生日期：</td>
                <td width="70%">
<%--                    onclick="laydate({istime: true, format: 'YYYY-MM-DD'})"--%>
                    <input type="text" name="birthday" value="" id="test1" >
                </td>
            </tr>
            <tr>
                <td width="15%">党员类型：</td>
                <td width="70%">
                    <select name="memberType" id="memberType" style="width:205px;height:28px;">

                    </select>
                </td>
            </tr>
            <tr>
                <td width="15%">入党日期：</td>
                <td width="70%">
                    <input type="text" name="admissionDate1" value="" id="test2">
                </td>
            </tr>
            <tr>
                <td width="15%">工作岗位：</td>
                <td width="70%">
                    <input type="text" name="post" value="">
                </td>
            </tr>
            <tr>
                <td width="15%">学历：</td>
                <td width="70%">
                    <input type="text" name="education" value="">
                </td>
            </tr>
            <tr>
                <td width="15%">联系方式：</td>
                <td width="70%">
                    <input type="text" name="tel" value="">
                </td>
            </tr>
            <tr>
                <td width="15%">转正日期：</td>
                <td width="70%">
                    <input type="text" name="becomeDate1" value="" id="test3">
                </td>
            </tr>
            <tr>
                <td width="15%">党籍状态：</td>
                <td width="70%">
                    <input type="text" name="partyState" value="">
                </td>
            </tr>
            <tr>
                <td width="15%">家庭地址：</td>
                <td width="70%">
                    <input type="text" name="address" value="">
                </td>
            </tr>
            <tr>
                <td width="15%">家庭地址坐标：</td>
                <td width="70%">
                    <label style="width: 80%;position:relative">
                        <input type="text" name="addressLocation" style="width:200px" readonly="readonly">
                        <button type="button" class="dwbtn" style="position: absolute;width: 62px;height: 28px; background-color: #228cdc;color: #fff; right: 6px;top:-3px;border-radius: 3px;cursor: pointer;">点击定位</button>
                    </label>
                </td>
            </tr>
            <tr>
                <td width="15%">是否是失联党员：</td>
                <td width="70%">
                    <label style="width: 80%;position:relative">
                        <input type="radio" value="1" name="contactNos" style="width:16px;height:16px;" >
                        <span>是</span>
                        <input type="radio" value="0" name="contactNos" style="width:16px;height:16px;" >
                        <span>否</span>
                    </label>
                </td>
            </tr>
            <tr>
                <td width="15%">失联日期：</td>
                <td width="70%">
                    <input type="text" name="contactDate" value="" id="test4">
                </td>
            </tr>
            <tr>
                <td width="15%">是否为流动党员：</td>
                <td width="70%">
                    <label style="width: 80%;position:relative">
                        <input type="radio" value="1" name="flowMemberNos" style="width:16px;height:16px;" >
                        <span>是</span>
                        <input type="radio" value="0" name="flowMemberNos" style="width:16px;height:16px;" >
                        <span>否</span>
                    </label>
                </td>
            </tr>
            <tr>
                <td width="15%">外出流向：</td>
                <td width="70%">
                    <input type="text" name="extrMember" value="" >
                </td>
            </tr>
            <%--<tr>--%>
                <%--<td width="15%">党员类型：</td>--%>
                <%--<td width="70%">--%>
                    <%--<div class="partyType">--%>
                        <%--&lt;%&ndash;<label style="margin-right:20px;">&ndash;%&gt;--%>
                            <%--&lt;%&ndash;<input type="checkbox" style="width:16px;height:16px;">&ndash;%&gt;--%>
                            <%--&lt;%&ndash;<span>撒地方</span>&ndash;%&gt;--%>
                        <%--&lt;%&ndash;</label>&ndash;%&gt;--%>
                        <%--<input type="hidden" name="memberTypeTo">--%>

                    <%--</div>--%>
                <%--</td>--%>
            <%--</tr>--%>
            <tr>
                <td colspan="2">
                    <div class="div_btn">
                        <input type="button" class="inpuBtn new_liucheng" id="btn1"
                               value="<fmt:message code="global.lang.save" />"/>
                        <input type="button" class="inpuBtn backCanBtn" style="padding-left: 28px;" id="btn2"
                               onclick="window.close()" value="<fmt:message code="global.lang.close" />"/>
                    </div>

                </td>
            </tr>


        </table>
    </form>
</div>
<script>
    layui.use('laydate', function() {
        var laydate = layui.laydate;

        //常规用法
        laydate.render({
            elem: '#test1'
        });
        laydate.render({
            elem: '#test2'
        });
        laydate.render({
            elem: '#test3'
        });
        laydate.render({
            elem: '#test4'
        });
    })

        $('.userAdd').click(function(){
        user_id="staffNameInput";
        $.popWindow("../../common/selectUser?0");
    });
    //    点击坐标定位
    $('.dwbtn').click(function () {
       // window.open('/street/chooseMap')
      window.open('/street/mapCoordinates?type=4');
    })
    //    设置坐标
    function setZuobiao(str){
        $('input[name="addressLocation"]').val(str)
    }
    function getParty(){
        $.ajax({
            url:'/code/GetDropDownBox',
            data:{CodeNos:'MEMBER_TYPE'},
            dataType:'json',
            success:function(res){
                var str='<option vlaue="">请选择</option>'
                var data= res.MEMBER_TYPE;
                for(var i=0;i<data.length;i++){
                    str += '<option value="'+data[i].codeNo+'">'+data[i].codeName+'</option>'
                }
                $('#memberType').html(str)
            }
        })
        $.ajax({
            url:'/code/GetDropDownBox',
            data:{CodeNos:'MEMBER_TYPE_TO'},
            dataType:'json',
            success:function(res){
                var str=''
                var data= res.MEMBER_TYPE_TO;
                for(var i=0;i<data.length;i++){
                    str += '  <label style="margin-right:20px;"> ' +
                        '<input type="checkbox" class="check" style="width:16px;height:16px;" value="'+data[i].codeNo+'"> ' +
                        '<span>'+data[i].codeName+'</span> ' +
                        '</label>'
                }
                $('.partyType').html(str)
            }
        })
    }
    $(function () {
        getParty();
        if (party.type) {
            $('.titleTxt').html('新增党员')
            $('#department').deptSelect(function (me) {
                $(me).val(window.opener.numdept)
                $(me).append('<option value="0"><fmt:message code="userManagement.th.Outgoing" /></option>')
            });
        } else {
            detail();
            $('.userAdd').css('display','none')
            $('.titleTxt').html('编辑党员')
            $('input[name="userId"]').prop('readonly', true);
            $('input[name="userId"]').css('background', '#E3E3E3');

        }


    });




    function isCardID(sId) {
        var iSum = 0;
        var info = "";
        if (!/^\d{17}(\d|x)$/i.test(sId)) return "你输入的身份证长度或格式错误";
        sId = sId.replace(/x$/i, "a");
        if (aCity[parseInt(sId.substr(0, 2))] == null) return "你的身份证地区非法";
        sBirthday = sId.substr(6, 4) + "-" + Number(sId.substr(10, 2)) + "-" + Number(sId.substr(12, 2));
        var d = new Date(sBirthday.replace(/-/g, "/"));
        if (sBirthday != (d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate()))return "身份证上的出生日期非法";
        for (var i = 17; i >= 0; i--) iSum += (Math.pow(2, i) % 11) * parseInt(sId.charAt(17 - i), 11);
        if (iSum % 11 != 1) return "你输入的身份证号非法";
        //aCity[parseInt(sId.substr(0,2))]+","+sBirthday+","+(sId.substr(16,1)%2?"男":"女");//此次还可以判断出输入的身份证号的人性别
        return true;
    }
    /******************************************************验证用户输入******************************************************/


    function ValidateInput(element, value) {
//验证密码
        if (element == "password") {
            if (value.toString().length < 6) {
                /* alert("您的密码不到6位")*/
                return;
            }

        }
    }


    /*================================密码强度 ===========Begin=======================================*/

    function Evaluate(word) {
        var regLow = /^[0-9]*$/;
        var regMetih = /^[A-Za-z0-9]+$/
        var regHeight = /[0-9a-zA-Z\._\$%&\*\!]/
        if (regLow.exec(word)) {
            return 1;
        } else if (regMetih.exec(word)) {
            return 2;
        } else if (regHeight.exec(word)) {
            return 3;
        } else {
            return 1;
        }
    }
    function colorInit() {
        $('#low').css("backgroundColor", "#fff")
        $('#medium').css("backgroundColor", "#fff")
        $('#height').css("backgroundColor", "#fff")

    }
    function validatePwdStrong(value) {

        if (Evaluate(value) == 1) {
            colorInit();
            $('#low').css("backgroundColor", "red")
            $('#medium').css("backgroundColor", "#fff")
            $('#height').css("backgroundColor", "#fff")

        }
        else if (Evaluate(value) == 2) {
            colorInit();
            $('#low').css("backgroundColor", "#dfff36")
            $('#medium').css("backgroundColor", "#dfff36")
            $('#height').css("backgroundColor", "#fff")

        }
        else if (Evaluate(value) == 3) {
            colorInit();
            $('#low').css("backgroundColor", "#2dff44")
            $('#medium').css("backgroundColor", "#2dff44")
            $('#height').css("backgroundColor", "#2dff44")
            $('#height').css("width", "70")

        }


    }
</script>


</body>
</html>
